/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.agtranscontinental.sisref.managedbean;

import com.agtranscontinental.sisref.sessionremote.PersonalEjbRemote;
import com.agtranscontinental.sisref.backingbean.LoginDto;
import com.agtranscontinental.sisref.commons.Encripta;
import com.agtranscontinental.sisref.commons.UParametro;
import com.agtranscontinental.sisref.commons.UProperties;
import com.agtranscontinental.sisref.util.Faces;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author ericson
 */
@ManagedBean
@RequestScoped
public class Login {

    @EJB
    PersonalEjbRemote ejbPersonal;
    
    private LoginDto ldto;

    /**
     * Creates a new instance of Login
     */
    public Login() {
        ldto = new LoginDto();
    }

    public String isUsuario(){
        String password=Encripta.encriptar(ldto.getClave(), Encripta.HASH_SHA1);
        ldto.setPersonal(ejbPersonal.getPersonal(ldto.getUsuario(), password));
        if(ldto.getPersonal()!=null){
            return "/pages/main.xhtml?faces-redirect=true";
        }else{
            String mensaje = UProperties.getMessage(UParametro.RUTA_MENSAJES, "USUA_PASSWORD_INCO");
            Faces.addMessage(mensaje, "frmLogin:msgErrorLogin", FacesMessage.SEVERITY_ERROR);
        }
        return "";
    }
    
    /**
     * @return the ldto
     */
    public LoginDto getLdto() {
        return ldto;
    }

    /**
     * @param ldto the ldto to set
     */
    public void setLdto(LoginDto ldto) {
        this.ldto = ldto;
    }

}
